Partícula en una caja – analítica

Partícula en una caja – analítica

from pylab import *
import seaborn as sns
from ipywidgets import *
(1)\[\begin{align} E_n = \bigg( \frac{h^2}{8m}\bigg) \frac{1}{\ell^2} n^2 \end{align}\]
(2)\[\begin{align} \psi(x) = \sqrt{\frac{2}{\ell}} \sin\bigg( \frac{n\pi x}{\ell} \bigg) \end{align}\]
π          = pi
# Physical quantities
e          = 1.602e-19
h          = 4.135667               # eV fs
c          = 299792458              # [m/s]
massfactor = e/c/c                  # 1 eV/c^2 = 1.79e-36 kg
me         = 9.109e-31/massfactor   # [eV/c^2] = 0.5x10^6 eV/c^2   
c_nmfs     = 299.792458             # [nm/fs]
         = h*h*c_nmfs*c_nmfs/8/me # eV nm^2

# Number of levels to show
nmax       = 5
n          = arange(nmax)+1

          = 1                      # nm

E          = //*n*n

x          = linspace(0,,1000)
ψ          = array( [ sqrt(2/)*sin(nv*π*x/) for nv in n] )
ψ2         = ψ*ψ
fig,axes = plt.subplots(ncols=2,nrows=1,figsize=(11,5))

axes[0].set_xlim(-.4*  ,1.4*)

color_list = sns.cubehelix_palette(nmax)

for i in arange(nmax):
    axes[0].plot(x,E[i]+ψ[i],label=r"$E_{0}$={1:>8.3f}".format(i+1,E[i]),c=color_list[i])

for i in arange(nmax):
    axes[0].plot([0 ,],[E[i],E[i]],'--',c=color_list[i])

    

axes[0].plot([0,0],[0,(ψ.max()+E[-1])*1.1],c="Gray")
axes[0].plot([,],[0,(ψ.max()+E[-1])*1.1],c="Gray")
axes[0].plot([0,],[0,0],c="Gray")

axes[0].set_xlabel("$x$ [nm]",fontsize=16)
axes[0].set_ylabel("$E$ [eV]",fontsize=16)
axes[0].legend(loc=1)
axes[0].set_title(r"$\psi$")

axes[1].set_xlim(-.4*  ,1.4*)

color_list = sns.cubehelix_palette(nmax)

for i in arange(nmax):
    axes[1].plot(x,E[i]+ψ2[i],label=r"$E_{0}$={1:>8.3f}".format(i+1,E[i]),c=color_list[i])

for i in arange(nmax):
    axes[1].plot([0 ,],[E[i],E[i]],'--',c=color_list[i])

    

axes[1].plot([0,0],[0,(ψ2.max()+E[-1])*1.1],c="Gray")
axes[1].plot([,],[0,(ψ2.max()+E[-1])*1.1],c="Gray")
axes[1].plot([0,],[0,0],c="Gray")

axes[1].set_xlabel("$x$ [nm]",fontsize=16)
axes[1].set_ylabel("$E$ [eV]",fontsize=16)
axes[1].legend(loc=1)
axes[1].set_title(r"$|\psi|^2$")


fig.tight_layout()
# fig.savefig("Cap2_OneDimensionalBox.pdf")
_images/Cap2_OneDimensionalBoxInteractive_4_0.png

Evolución temporal

π          = pi
# Physical quantities
e          = 1.602e-19
h          = 4.135667               # eV fs
ħ          = h/2/π                  # eV fs
c          = 299792458              # [m/s]
massfactor = e/c/c                  # 1 eV/c^2 = 1.79e-36 kg
me         = 9.109e-31/massfactor   # [eV/c^2] = 0.5x10^6 eV/c^2   
c_nmfs     = 299.792458             # [nm/fs]
         = h*h*c_nmfs*c_nmfs/8/me # eV nm^2

# Number of levels to show
nmax       = 5
n          = arange(nmax)+1

          = 1                      # nm

E          = //*n*n

x          = linspace(0,,1000)
ψ          = array( [ sqrt(2/)*sin(nv*π*x/) for nv in n] )
color_list = sns.cubehelix_palette(nmax)
@interact(t=(0,10,0.01))
def Evolution(t=0.0):
    fig,axes = plt.subplots(ncols=3,nrows=1,figsize=(16,5))
    axes[0].set_xlim(-.4*  ,1.4*)
    axes[1].set_xlim(-.4*  ,1.4*)
    axes[2].set_xlim(-.4*  ,1.4*)
    
    axes[0].set_ylim(-2,2*nmax+2)
    axes[1].set_ylim(-2,2*nmax+2)
    axes[2].set_ylim(-2,2*nmax+2)
    

    
    for nv in n:
        
        i = nv - 1
        E  = //*nv*nv
        Ψe = exp(-1.J*E*t/ħ)*sqrt(2/)*sin(nv*π*x/)
        Ψe2 = conjugate(Ψe)*Ψe
        
        axes[0].plot(x,E+Ψe.real,label=r"$E_{0}$={1:>8.3f}".format(i+1,E),c=color_list[i])
        axes[0].plot([0 ,],[E,E],'--',c=color_list[i])
        
        axes[1].plot(x,E+Ψe.imag,label=r"$E_{0}$={1:>8.3f}".format(i+1,E),c=color_list[i])
        axes[1].plot([0 ,],[E,E],'--',c=color_list[i])
        
        axes[2].plot(x,E+Ψe2.real,label=r"$E_{0}$={1:>8.3f}".format(i+1,E),c=color_list[i])
        axes[2].plot([0 ,],[E,E],'--',c=color_list[i])
        
    axes[0].plot([0,0],[0,2*nmax+2],c="Gray")
    axes[0].plot([,],[0,2*nmax+2],c="Gray")
    axes[0].plot([0,],[0,0],c="Gray")
    
    axes[0].set_xlabel("$x$ [nm]",fontsize=16)
    axes[0].set_ylabel("$E$ [eV]",fontsize=16)
    axes[0].legend(loc=1)
    axes[0].set_title(r"Re $(\psi)$")
    
    axes[1].plot([0,0],[0,2*nmax+2],c="Gray")
    axes[1].plot([,],[0,2*nmax+2],c="Gray")
    axes[1].plot([0,],[0,0],c="Gray")
    
    axes[1].set_xlabel("$x$ [nm]",fontsize=16)
    axes[1].set_ylabel("$E$ [eV]",fontsize=16)
    axes[1].legend(loc=1)
    axes[1].set_title(r"Im $(\psi)$")
    
    axes[2].plot([0,0],[0,2*nmax+2],c="Gray")
    axes[2].plot([,],[0,2*nmax+2],c="Gray")
    axes[2].plot([0,],[0,0],c="Gray")
    
    axes[2].set_xlabel("$x$ [nm]",fontsize=16)
    axes[2].set_ylabel("$E$ [eV]",fontsize=16)
    axes[2].legend(loc=1)
    axes[2].set_title(r"$|\psi|^2$")
    return
        

Ortogonalidad

ψ  = array( [ sqrt(2/)*sin(nv*π*x/) for nv in n] )

print( np.trapz( np.conj(ψ[0])*ψ[0],x ) )
1.0000000000000002

Operadores

\[\begin{align*} \langle x \rangle &=&\frac{a}{2} \\ \langle x^2 \rangle &=& \bigg( \frac{1}{3}-\frac{1}{2\pi^2} \bigg)a^2 \end{align*}\]
xmean = np.trapz( np.conj(ψ[0])*x*x*ψ[0],x  )
print (xmean)
print (1/3-1/2/pi/pi)
0.2826727415118342
0.2826727415121644
\[\begin{align*} \langle p_x \rangle &=&0 \\ \langle p_x^2 \rangle &=& \bigg( \frac{h^2}{4a^2} \bigg) \end{align*}\]
ħ = h/2/π
 = np.gradient(ψ[0],x,edge_order=2)
pmean = np.trapz( np.conj(ψ[0])*,x )
print (pmean)
-7.771561172376096e-16
d2ψ = np.gradient(,x,edge_order=2)
p2mean = np.trapz( np.conj(ψ[0])*d2ψ,x )
print (-ħ*ħ*p2mean)
4.275921330628969
h*h/4
4.275935383722249
plot(x,ψ[0])
plot(x,)
plot (x,d2ψ)
[<matplotlib.lines.Line2D at 0x7f1f386582e8>]
_images/Cap2_OneDimensionalBoxInteractive_18_1.png
widgets.IntSlider(
    value=7,
    min=0,
    max=10,
    step=1,
    description='Test:',
    disabled=False,
    continuous_update=False,
    orientation='horizontal',
    readout=True,
    readout_format='d'
)
tab_contents = ['P0', 'P1', 'P2', 'P3', 'P4']
children = [widgets.Text(description=name) for name in tab_contents]
tab = widgets.Tab()
tab.children = children
for ii in range(len(children)):
    tab.set_title(ii, f"tab_{ii}")
tab
import plotly.io as pio
import plotly.express as px
import plotly.offline as py

df = px.data.iris()
fig = px.scatter(df, x="sepal_width", y="sepal_length", color="species", size="sepal_length")
fig.show()
import plotly.express as px
data = px.data.iris()
data.head()
sepal_length sepal_width petal_length petal_width species species_id
0 5.1 3.5 1.4 0.2 setosa 1
1 4.9 3.0 1.4 0.2 setosa 1
2 4.7 3.2 1.3 0.2 setosa 1
3 4.6 3.1 1.5 0.2 setosa 1
4 5.0 3.6 1.4 0.2 setosa 1
# Import the necessaries libraries
import plotly.offline as pyo
import plotly.graph_objs as go
# Set notebook mode to work in offline
pyo.init_notebook_mode()
# Create traces
trace0 = go.Scatter(
    x=[1, 2, 3, 4],
    y=[10, 15, 13, 17]
)
trace1 = go.Scatter(
    x=[1, 2, 3, 4],
    y=[16, 5, 11, 9]
)
# Fill out data with our traces
data = [trace0, trace1]
# Plot it and save as basic-line.html
pyo.iplot(data, filename = 'basic-line')